<template>
  <div class="SystemManagement">
    <el-tabs v-model="activeName1" type="card" @tab-click="handleClick">
      <el-tab-pane label="公司级" name="first"></el-tab-pane>
    </el-tabs>
    <div style="display: flex">
      <div class="in_concent_left_1">
        <div
          v-for="(value, index) in tabs1Data"
          :key="index"
          :class="[
            'in_concent_left_pitch',
            pitchvalue1 == index ? 'choose_itch' : '',
          ]"
          @click="choosePitch1(index)"
        >
          {{ value }}
        </div>
      </div>
      <div class="in_concent_left_2">
        <div
          v-for="(value, index) in tabs2Data"
          :key="index"
          :class="[
            'in_concent_left_pitch',
            pitchvalue2 == index ? 'choose_itch' : '',
          ]"
          @click="choosePitch2(index)"
        >
          {{ value }}
        </div>
      </div>
      <div style="flex: 1; overflow-y: scroll; height: 520px">
        <div class="systemtab" v-if="pitchvalue1 === 0 && pitchvalue2 === 0">
          <div class="systemconcent">
            <div style="width: 100%">
              <div class="tableTitle" style="padding: 0 20px">
                <div>订单号生成规则</div>
                <div style="width: 100%">
                  <div
                    v-for="(item, index) in tableData5[0].item_info"
                    :key="index"
                    style="display: inline-block; padding: 10px 10px 10px 0px"
                  >
                    <div v-if="index == tableData5[0].item_info.length - 1">
                      <div style="float: right; padding: 0px 0px 13px 0px">
                        <el-button
                          icon="el-icon-plus"
                          v-if="index == tableData5[0].item_info.length - 1"
                          @click="addInput"
                          circle
                          style="margin-left: 10px"
                          size="mini"
                        ></el-button>
                        <el-button
                          icon="el-icon-minus"
                          v-if="index == tableData5[0].item_info.length - 1"
                          @click="removeInput"
                          size="mini"
                          circle
                        ></el-button>
                      </div>
                    </div>
                    <div v-else>
                      <div style="padding-bottom: 5px">
                        <el-select
                          v-model="item.key"
                          placeholder="请选择"
                          style="width: 100px"
                          v-if="index == 0"
                          :disabled="parentdis"
                          :key="index"
                        >
                          <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          >
                          </el-option>
                        </el-select>
                        <el-select
                          v-model="item.key"
                          placeholder="请选择"
                          style="width: 100px"
                          v-else
                          :key="index"
                          @change="clearValue(item, index)"
                        >
                          <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          >
                          </el-option>
                        </el-select>
                      </div>
                      <div>
                        <div v-if="item.key == 1 || item.key == 2">
                          <el-input
                            v-model="item.value"
                            style="width: 100px"
                            placeholder="请输入内容"
                            :key="index"
                            @blur="castAbout(item, index)"
                          ></el-input>
                        </div>
                        <div v-else-if="item.key == 3">
                          <el-select
                            v-model="item.value"
                            placeholder="请选择"
                            style="width: 100px"
                          >
                            <el-option
                              v-for="item in yearoptions"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </div>
                        <!-- <div v-else-if="item.key==4 || item.key==5 ||item.key==6 ||item.key==7 || item.key==8">
                          <el-input v-model="monthDay" style="width: 100px;" placeholder="请输入内容"
                            :disabled="parentdis"></el-input>
                        </div> -->
                        <div v-else-if="item.key == 4">
                          <el-select
                            v-model="item.value"
                            placeholder="请选择"
                            style="width: 100px"
                          >
                            <el-option
                              v-for="item in serialNumber"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </div>
                        <div v-else>
                          <el-select
                            v-model="item.value"
                            placeholder="请选择"
                            style="width: 100px"
                          >
                            <el-option
                              v-for="item in options"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div>
                  <el-input
                    v-model="inputValue"
                    placeholder="生成的值"
                    :disabled="parentdis"
                  ></el-input>
                </div>
              </div>
            </div>
            <el-form
              ref="order_number_allow_input"
              label-width="230px"
              label-position="left"
              style="margin: 20px 0px 0px 20px"
            >
              <el-form-item>
                <template slot="label">
                  <div style="font-size: 14px">订单号支持定义</div>
                </template>
                <div class="radioclass">
                  <el-radio
                    label="1"
                    v-model="order_number_allow_input.item_value"
                    >开启</el-radio
                  >
                  <el-radio
                    label="0"
                    v-model="order_number_allow_input.item_value"
                    >关闭</el-radio
                  >
                </div>
              </el-form-item>
              <el-form-item>
                <template slot="label">
                  <div style="font-size: 14px">订单号是否混淆</div>
                </template>
                <div class="radioclass">
                  <el-radio
                    label="1"
                    v-model="order_number_weather_confuse.item_value"
                    >开启</el-radio
                  >
                  <el-radio
                    label="0"
                    v-model="order_number_weather_confuse.item_value"
                    >关闭</el-radio
                  >
                </div>
              </el-form-item>
            </el-form>
            <div class="tableArea">
              <div class="tableTitle">订单必填项设置</div>
              <el-table :data="tableData1" key="1">
                <el-table-column prop="title" label="字段" width="260">
                  <template slot-scope="scope">
                    {{ scope.row.title }}
                    <el-tooltip placement="top" effect="light">
                      <div slot="content" v-if="scope.row.title === '提货时间'">
                        订单的提货时间必填项设置与运单的提货时间设置一致。
                      </div>
                      <div slot="content" v-if="scope.row.title === '订单时效'">
                        订单的时效必填项设置与运单的时效设置一致。
                      </div>
                      <i class="header-icon el-icon-info"></i>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column label="必填项设置">
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.item_value">
                      <el-radio label="1">{{ scope.row.label2 }}</el-radio>
                      <el-radio label="0">{{ scope.row.label1 }}</el-radio>
                    </el-radio-group>
                  </template>
                </el-table-column>
              </el-table>
              <div class="tableTitle" style="margin-top: 10px">
                订单默认项设置
              </div>
              <el-table :data="tableData2" key="2">
                <el-table-column prop="title" label="字段" width="260">
                </el-table-column>
                <el-table-column label="必填项设置">
                  <template slot-scope="scope">
                    <el-radio-group
                      v-model="scope.row.item_value"
                      v-if="scope.row.item_name !== 'receipt'"
                    >
                      <el-radio label="0">{{ scope.row.label1 }}</el-radio>
                      <el-radio label="1">{{ scope.row.label2 }}</el-radio>
                      <el-radio label="2" v-if="scope.row.label3">{{
                        scope.row.label3
                      }}</el-radio>
                    </el-radio-group>
                    <el-checkbox-group v-model="scope.row.item_value" v-else>
                      <!-- <el-checkbox :label="scope.row.label1"> </el-checkbox>
                      <el-checkbox :label="scope.row.label2"></el-checkbox> -->
                      <el-checkbox label="客户回单"></el-checkbox>
                      <el-checkbox label="我司运单"></el-checkbox>
                    </el-checkbox-group>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div>
              <el-form
                ref="form"
                :model="form"
                label-width="230px"
                label-position="left"
                style="margin: 20px 0px 0px 20px"
              >
                <el-form-item>
                  <template slot="label">
                    <div style="font-size: 14px">订单自动受理</div>
                  </template>
                  <div class="radioclass">
                    <el-radio label="1" v-model="auto_accept.item_value"
                      >开启</el-radio
                    >
                    <el-radio label="0" v-model="auto_accept.item_value"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label">
                    <div style="font-size: 14px">包装数量包装型号不展示</div>
                  </template>
                  <div>
                    <!-- <div class="radioclass">
                      <el-radio label="1" v-model="show_package_type_quantity.item_value">开启</el-radio>
                      <el-radio label="0" v-model="show_package_type_quantity.item_value">关闭</el-radio>
                    </div> -->
                    <div style="margin: 0px 0px 0px 40px">
                      <el-select
                        v-model="show_package_type_quantity.item_info"
                        filterable
                        placeholder="请选择所属客户"
                        multiple
                        style="width: 98%"
                      >
                        <el-option
                          v-for="(item, index) in customerBoxData"
                          :key="index"
                          :value="item.id"
                          :label="item.name"
                        ></el-option>
                      </el-select>
                    </div>
                  </div>
                </el-form-item>
                <el-form-item v-permission="'system_setting_update'">
                  <el-button
                    data-tracker="P61-1"
                    type="primary"
                    @click="onSubmit()"
                    >保存</el-button
                  >
                  <el-button data-tracker="P61-2" @click="cancel()"
                    >取消</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
        <div class="systemtab" v-if="pitchvalue1 === 1 && pitchvalue2 === 0">
          <div class="systemconcent">
            <div class="tableArea">
              <div class="tableTitle">运单必填项校验</div>
              <el-table :data="tableData3" key="3">
                <el-table-column prop="title" label="字段" width="300">
                </el-table-column>
                <el-table-column label="必填项设置">
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.item_value">
                      <el-radio label="1">{{ scope.row.label2 }}</el-radio>
                      <el-radio label="0">{{ scope.row.label1 }}</el-radio>
                    </el-radio-group>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div>
              <el-form
                ref="form"
                :model="form"
                label-width="270px"
                label-position="left"
                style="margin: 20px 0px 0px 20px"
              >
                <el-form-item label="订单自动转运单">
                  <template slot="label">
                    订单自动转运单
                    <el-tooltip placement="top" effect="light">
                      <div slot="content">
                        订单需满足运单必填项校验才能自动转运单。
                      </div>
                      <i class="header-icon el-icon-info"></i>
                    </el-tooltip>
                  </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.order_auto_waybill.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.order_auto_waybill.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item label="运输环节铆钉逻辑">
                  <template slot="label">
                    运输环节铆钉逻辑
                    <el-tooltip placement="top" effect="light">
                      <div slot="content">
                        揽收、干线、配送、签收、回单，已<br />完成上一环节才能进行下一环节。
                      </div>
                      <i class="header-icon el-icon-info"></i>
                    </el-tooltip>
                  </template>
                  <div class="radioclass">
                    <el-radio v-model="form.maoding_switch.item_value" label="1"
                      >开启</el-radio
                    >
                    <el-radio v-model="form.maoding_switch.item_value" label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item label="运输环节完成后不可编辑">
                  <template slot="label">
                    运单、运输环节编辑开关
                    <el-tooltip placement="top" effect="light">
                      <div slot="content">
                        1、每月1号至5号可以修改上月+本月修改的运单、环节单，<br />
                        每月6号至最后1天，可以修改当月的运单，环节单<br />
                        2、以运单、各个环节单的操作时间为判断依据
                      </div>
                      <i class="header-icon el-icon-info"></i>
                    </el-tooltip>
                  </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.edit_after_node_finish.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.edit_after_node_finish.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item label="业务由客户所属区域负责">
                  <div class="radioclass">
                    <el-radio
                      v-model="
                        form.data_view_distinguish_transport_type.item_value
                      "
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="
                        form.data_view_distinguish_transport_type.item_value
                      "
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label">
                    货物件数、重量、体积、包装数量<br />
                    在运输中的一致性校验
                  </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.number_verify_switch.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.number_verify_switch.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label"> 出发、目的网点可编辑 </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.waybill_branch_edit.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.waybill_branch_edit.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label"> 运输环节的费用项校验 </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.fee_entry.item_value"
                      label="0"
                      disabled
                      >创建时校验</el-radio
                    >
                    <el-radio v-model="form.fee_entry.item_value" label="1"
                      >运输环节完成时校验</el-radio
                    >
                    <el-radio v-model="form.fee_entry.item_value" label="2"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label"> 成本超出原因是否填写 </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.cost_exceeds_reason_fill_switch.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.cost_exceeds_reason_fill_switch.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label"> 收入小于10，成本能否填写 </template>
                  <div class="radioclass">
                    <el-radio
                      v-model="form.income_cost_fill_switch.item_value"
                      label="1"
                      >开启</el-radio
                    >
                    <el-radio
                      v-model="form.income_cost_fill_switch.item_value"
                      label="0"
                      >关闭</el-radio
                    >
                  </div>
                </el-form-item>
                <el-form-item>
                  <template slot="label"> 允许调账 </template>
                  <div style="margin: 0px 0px 0px 40px">
                    <el-select
                      v-model="form.account_adjust_money_users.item_info"
                      filterable
                      placeholder="请选择用户"
                      multiple
                      style="width: 98%"
                    >
                      <el-option
                        v-for="(item, index) in usersList"
                        :key="index"
                        :value="item.id"
                        :label="item.name"
                      ></el-option>
                    </el-select>
                  </div>
                </el-form-item>
                <el-form-item v-permission="'system_setting_update'">
                  <el-button
                    data-tracker="P61-1"
                    type="primary"
                    @click="onSubmit()"
                    >保存</el-button
                  >
                  <el-button data-tracker="P61-2" @click="cancel()"
                    >取消</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
        <div class="systemtab" v-if="pitchvalue1 === 1 && pitchvalue2 === 1">
          <ChargeList></ChargeList>
        </div>
        <div
          style="height: 600px"
          v-if="pitchvalue1 === 1 && pitchvalue2 === 2"
        >
          <el-form
            ref="form"
            :model="form"
            label-position="left"
            label-width="400px"
            style="margin: 20px 0px 0px 20px"
          >
            <el-form-item
              label="揽收完成时，校验运单信息的必填项"
              label-width="470px"
            >
              <div class="radioclass">
                <el-radio
                  label="1"
                  v-model="
                    form.collect_finish_waybill_params_required_check.item_value
                  "
                  >开启</el-radio
                >
                <el-radio
                  label="0"
                  v-model="
                    form.collect_finish_waybill_params_required_check.item_value
                  "
                  >关闭</el-radio
                >
              </div>
            </el-form-item>
            <div class="tableArea">
              <el-form-item label="揽收完成时，必填项校验"> </el-form-item>
              <el-table :data="tableData4" key="4" style="margin-bottom: 10px">
                <el-table-column label="所属" prop="belong"> </el-table-column>
                <el-table-column prop="title" label="字段"> </el-table-column>
                <el-table-column label="必填项设置">
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.item_value">
                      <el-radio
                        label="1"
                        :disabled="
                          form.collect_finish_waybill_params_required_check
                            .item_value == 0
                        "
                        >必填</el-radio
                      >
                      <el-radio
                        label="0"
                        :disabled="
                          form.collect_finish_waybill_params_required_check
                            .item_value == 0
                        "
                        >非必填</el-radio
                      >
                    </el-radio-group>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <!-- <el-form-item
              label="同步揽收货物信息到运单货物信息"
              label-width="473px"
            >
              <div class="radioclass">
                <el-radio
                  label="1"
                  v-model="
                    form.collect_finish_waybill_params_required_check.item_value
                  "
                  >开启</el-radio
                >
                <el-radio
                  label="0"
                  v-model="
                    form.collect_finish_waybill_params_required_check.item_value
                  "
                  >关闭</el-radio
                >
              </div>
            </el-form-item> -->
            <el-form-item v-permission="'system_setting_update'">
              <el-button data-tracker="P61-1" type="primary" @click="onSubmit()"
                >保存</el-button
              >
              <el-button data-tracker="P61-2" @click="cancel()">取消</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="systemtab" v-if="pitchvalue1 === 1 && pitchvalue2 === 4">
          <el-form
            ref="form"
            :model="form"
            label-position="left"
            label-width="400px"
            style="margin: 20px 0px 0px 20px"
          >
            <el-form-item label="签收时间不可编辑" label-width="470px">
              <div class="radioclass">
                <el-radio
                  label="1"
                  v-model="form.sign_time_control_switch.item_value"
                  >开启</el-radio
                >
                <el-radio
                  label="0"
                  v-model="form.sign_time_control_switch.item_value"
                  >关闭</el-radio
                >
              </div>
            </el-form-item>
            <div style="margin-top: 50px">
              <el-form-item>
                <el-button
                  data-tracker="P61-1"
                  type="primary"
                  @click="onSubmit()"
                  >保存</el-button
                >
                <el-button data-tracker="P61-2" @click="cancel()"
                  >取消</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="systemtab" v-if="pitchvalue1 === 1 && pitchvalue2 === 3">
          <el-form
            ref="form"
            :model="form"
            label-position="left"
            label-width="400px"
            style="margin: 20px 0px 0px 20px"
          >
            <el-form-item label="配送完成" label-width="470px">
              <div class="radioclass">
                <el-radio
                  label="1"
                  v-model="form.distribution_finish_switch.item_value"
                  >开启</el-radio
                >
                <el-radio
                  label="0"
                  v-model="form.distribution_finish_switch.item_value"
                  >关闭</el-radio
                >
              </div>
            </el-form-item>
            <div style="margin-top: 50px">
              <el-form-item>
                <el-button
                  data-tracker="P61-1"
                  type="primary"
                  @click="onSubmit()"
                  >保存</el-button
                >
                <el-button data-tracker="P61-2" @click="cancel()"
                  >取消</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="systemtab" v-if="pitchvalue1 === 2 && pitchvalue2 === 0">
          <CustomerServiceList></CustomerServiceList>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { settingList, settingCreate, numberRule } from "@/api/print";
import ChargeList from "./components/chargeList.vue";
import CustomerServiceList from "./components/customerServiceList.vue";
import { customerBox } from "@/api/Largewidthmeterlist";
import { reqHandlersList } from "@/api/waybill";
export default {
  name: "SystemManagement",
  components: {
    ChargeList,
    CustomerServiceList,
  },
  data() {
    return {
      pitchvalue1: 0,
      pitchvalue2: 0,
      tabs1Data: ["订单管理", "运单管理", "公司管理"],
      tabs2Data: ["基本设置"],
      usersList: [],
      activeName1: "first",
      tableData1: [
        {
          id: "",
          title: "提货时间",
          label1: "非必填",
          label2: "必填",
          item_name: "collect_time_required",
          item_value: "1",
        },
        {
          id: "",
          title: "订单时效",
          label1: "非必填",
          label2: "必填",
          item_name: "order_aging_required",
          item_value: "0",
        },
      ],
      tableData2: [
        {
          id: "",
          title: "送货方式",
          label1: "送货",
          label2: "自提",
          item_name: "delivery_method",
          item_value: "0",
        },
        {
          id: "",
          title: "紧急度",
          label1: "正常",
          label2: "加急",
          label3: "特急",
          item_name: "degree_of_urgency",
          item_value: "0",
        },
        {
          id: "",
          title: "回单默认值",
          label1: "客户回单",
          label2: "我司运单",
          item_name: "receipt",
          item_value: [],
        },
      ],
      tableData3: [
        {
          id: "",
          title: "运单时效",
          label1: "非必填",
          label2: "必填",
          item_name: "order_aging_required",
          item_value: "0",
        },
        {
          id: "",
          title: "提货时间",
          label1: "非必填",
          label2: "必填",
          item_name: "collect_time_required",
          item_value: "1",
        },
        {
          id: "",
          title: "运费",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_freight_required",
          item_value: "0",
        },
        {
          id: "",
          title: "出发网点",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_from_branch_required",
          item_value: "1",
        },
        {
          id: "",
          title: "目的网点",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_to_branch_required",
          item_value: "1",
        },
        {
          id: "",
          title: "发站",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_from_region_required",
          item_value: "1",
        },
        {
          id: "",
          title: "到站",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_to_region_required",
          item_value: "1",
        },
        {
          id: "",
          title: "路由",
          label1: "非必填",
          label2: "必填",
          item_name: "waybill_router_required",
          item_value: "0",
        },
      ],
      tableData4: [
        {
          id: "",
          belong: "运单",
          title: "运单时效",
          item_name: "collect_finish_aging_required",
          item_value: "1",
        },
        {
          id: "",
          belong: "运单",
          title: "货物信息",
          item_name: "collect_finish_waybill_goods_required",
          item_value: "1",
        },
        {
          id: "",
          belong: "运单",
          title: "运费",
          item_name: "collect_finish_freight_required",
          item_value: "1",
        },
        {
          id: "",
          belong: "运单",
          title: "出发网点",
          item_name: "collect_finish_from_branch_required",
          item_value: "1",
        },
        {
          id: "",
          belong: "运单",
          title: "目的网点",
          item_name: "collect_finish_to_branch_required",
          item_value: "1",
        },
        {
          id: "",
          belong: "揽收单",
          title: "温度计",
          item_name: "collect_finish_thermometer_required",
          item_value: "1",
        },
      ],
      auto_accept: {
        //订单自动受理
        id: "",
        item_name: "order_auto_accept",
        item_value: "1",
      },
      form: {
        edit_after_node_finish: {
          id: "",
          item_name: "edit_after_node_finish",
          item_value: "1",
        }, //运输环节完成后不可编辑
        maoding_switch: {
          id: "",
          item_name: "maoding_switch",
          item_value: "1",
        }, //运输环节铆钉逻辑
        data_view_distinguish_transport_type: {
          id: "",
          item_name: "data_view_distinguish_transport_type",
          item_value: "1",
        }, //非保温箱业务由客户所属区域负责
        order_auto_waybill: {
          id: "",
          item_name: "order_auto_waybill",
          item_value: "1",
        }, //订单转运单
        number_verify_switch: {
          id: "",
          item_name: "number_verify_switch",
          item_value: "1",
        }, //货物件数、重量、体积、包装数量一致性校验
        waybill_branch_edit: {
          id: "",
          item_name: "waybill_branch_edit",
          item_value: "1",
        }, //运单出发、目的网点可编辑
        fee_entry: {
          id: "",
          item_name: "fee_entry",
          item_value: "1",
        }, //运输环节的费用项校验:0创建时校验，1运输环节完成时校验，2关闭
        collect_finish_waybill_params_required_check: {
          id: "",
          item_name: "collect_finish_waybill_params_required_check",
          item_value: "1",
        },
        cost_exceeds_reason_fill_switch: {
          id: "",
          item_name: "cost_exceeds_reason_fill_switch",
          item_value: "1",
        },
        income_cost_fill_switch: {
          id: "",
          item_name: "income_cost_fill_switch",
          item_value: "1",
        },
        account_adjust_money_users: {
          id: "",
          item_name: "account_adjust_money_users",
          item_value: "1",
          item_info: [],
        },
        //揽收完成时校验运单信息
        // collect_finish_waybill_params_required_check: {
        //   id: "28",
        //   item_name: "collect_finish_waybill_params_required_check",
        //   item_value: "1",
        // }, //揽收完成时同步揽收货物信息
        // 签收时间可编辑
        sign_time_control_switch: {
          id: "",
          item_name: "sign_time_control_switch",
          item_value: "0",
        },
        // 配送管理
        distribution_finish_switch: {
          id: "",
          item_name: "distribution_finish_switch",
          item_value: "0",
        },
      },
      disabledfalse: true,
      options: [
        {
          value: "1",
          label: "固定字符",
        },
        {
          value: "2",
          label: "连接符",
        },
        {
          value: "3",
          label: "年月日",
        },
        {
          value: "4",
          label: "序列号",
        },
      ],
      yearoptions: [
        {
          value: "1",
          label: "6位",
        },
        {
          value: "2",
          label: "8位",
        },
      ],

      serialNumber: [
        {
          value: "2",
          label: "2位",
        },
        {
          value: "3",
          label: "3位",
        },
        {
          value: "4",
          label: "4位",
        },
        {
          value: "5",
          label: "5位",
        },
        {
          value: "6",
          label: "6位",
        },
        {
          value: "7",
          label: "7位",
        },
        {
          value: "8",
          label: "8位",
        },
      ],
      tableData5: [
        {
          id: "",
          item_name: "order_number_generate_rule",
          item_info: [
            { key: "1", value: "" },
            { key: "", value: "" },
          ],
          item_value: "1",
        },
      ],
      order_number_allow_input: {
        //订单自动受理
        id: "",
        item_name: "order_number_allow_input",
        item_value: "0",
      },
      order_number_weather_confuse: {
        //订单号支持定义
        id: "",
        item_name: "order_number_weather_confuse",
        item_value: "0",
      },
      inputValue: "",
      parentdis: true,
      monthDay: "2位",
      valDataList: [],
      show_package_type_quantity: {
        //订单自动受理
        id: "",
        item_name: "show_package_type_quantity",
        item_value: "1",
        item_info: [],
      },
      customerBoxData: [], // 所属客户
      logistics_node_sms_notice: {
        //订单自动受理
        id: "",
        item_name: "logistics_node_sms_notice",
        item_value: "1",
        item_info: "",
      },
      collect_update_order_waybill_goods: {
        //订单自动受理
        id: "",
        item_name: "collect_update_order_waybill_goods",
        item_value: "1",
        item_info: "",
      },
      waybill_collect_time_required: {
        //订单自动受理
        id: "",
        item_name: "waybill_collect_time_required",
        item_value: "1",
        item_info: "",
      },
    };
  },

  computed: {
    watchInputData() {
      return this.tableData5[0].item_info;
    },
  },
  watch: {
    watchInputData: {
      deep: true,
      handler(newval, oldval) {
        this.handleCheckedReturnReceipt();
      },
    },
  },

  mounted() {
    this.settingListObj();
    this.customerBoxFn(); // 所属客户
    this.getUsers();
  },

  methods: {
    async getUsers() {
      let result = await reqHandlersList({ branch_id: "1" });
      this.usersList = result.data;
    },
    addInput() {
      if (this.tableData5[0].item_info[0].value != "") {
        this.tableData5[0].item_info.push({ key: "", value: "" });
      } else {
        this.$message({
          message: "第一个固定字符不能为空",
          type: "warning",
        });
      }
    },
    removeInput() {
      if (this.tableData5[0].item_info.length > 2) {
        this.tableData5[0].item_info.splice(
          this.tableData5[0].item_info.length - 2,
          1
        );
      } else {
        this.$message({
          message: "最后属性不能删除",
          type: "warning",
        });
      }
    },
    choosePitch1(index) {
      this.settingListObj();
      this.pitchvalue1 = index;
      this.pitchvalue2 = 0;
      if (index === 0) {
        this.tabs2Data = ["基本设置"];
      } else if (index === 1) {
        this.tabs2Data = [
          "基本设置",
          "运输环节默认负责人",
          "揽收管理",
          "配送管理",
          "签收管理",
        ];
      } else if (index === 2) {
        this.tabs2Data = ["区域客服"];
      }
    },
    choosePitch2(index) {
      this.pitchvalue2 = index;
    },
    handleClick(val) {
      // console.log(val);
    },
    changeActiveName2() {
      this.settingListObj();
    },
    onSubmit() {
      var show_package_type_quantitydata = {
        ...this.show_package_type_quantity,
        item_info: this.show_package_type_quantity.item_info.toString(),
      };
      // console.log(this.form.waybill_branch_edit);
      var param;
      if (this.pitchvalue1 === 0) {
        param = {
          settings: [
            ...this.tableData1.map((item) => {
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
              };
            }),
            ...this.tableData3.slice(2).map((item) => {
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
              };
            }),
            ...this.tableData2.map((item) => {
              if (item.item_name !== "receipt") {
                return {
                  id: item.id,
                  item_name: item.item_name,
                  item_value: item.item_value,
                };
              } else {
                var valueType = 0;
                if (
                  item.item_value.indexOf("客户回单") != -1 &&
                  item.item_value.indexOf("我司运单") != -1
                ) {
                  valueType = "3";
                } else if (
                  item.item_value.indexOf("我司运单") != -1 &&
                  item.item_value.indexOf("客户回单") == -1
                ) {
                  valueType = "1";
                } else if (
                  item.item_value.indexOf("客户回单") != -1 &&
                  item.item_value.indexOf("我司运单") == -1
                ) {
                  valueType = "0";
                } else {
                  valueType = "2";
                }
                return {
                  id: item.id,
                  item_name: item.item_name,
                  item_value: valueType,
                };
              }
            }),
            ...this.tableData4.map((item) => {
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
              };
            }),
            ...this.tableData5.map((item) => {
              var arr = item.item_info.filter((obj) => obj.key !== "");
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
                item_info: JSON.stringify(arr),
              };
            }),
            this.order_number_allow_input,
            this.order_number_weather_confuse,
            this.auto_accept,
            this.form.data_view_distinguish_transport_type,
            this.form.edit_after_node_finish,
            this.form.maoding_switch,
            this.form.order_auto_waybill,
            this.form.number_verify_switch,
            this.form.waybill_branch_edit,
            this.form.fee_entry,
            this.form.collect_finish_waybill_params_required_check,
            this.form.cost_exceeds_reason_fill_switch,
            this.form.income_cost_fill_switch,
            this.form.account_adjust_money_users,
            this.form.sign_time_control_switch,
            this.form.distribution_finish_switch,
            show_package_type_quantitydata,
            this.logistics_node_sms_notice,
            this.collect_update_order_waybill_goods,
            this.waybill_collect_time_required,
            // this.form.collect_finish_waybill_params_required_check,
          ],
        };
      } else {
        param = {
          settings: [
            ...this.tableData3.map((item) => {
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
              };
            }),
            ...this.tableData2.map((item) => {
              if (item.item_name !== "receipt") {
                return {
                  id: item.id,
                  item_name: item.item_name,
                  item_value: item.item_value,
                };
              } else {
                var valueType = 0;

                if (
                  item.item_value.indexOf("客户回单") != -1 &&
                  item.item_value.indexOf("我司运单") != -1
                ) {
                  valueType = "3";
                } else if (
                  item.item_value.indexOf("我司运单") != -1 &&
                  item.item_value.indexOf("客户回单") == -1
                ) {
                  valueType = "1";
                } else if (
                  item.item_value.indexOf("客户回单") != -1 &&
                  item.item_value.indexOf("我司运单") == -1
                ) {
                  valueType = "0";
                } else {
                  valueType = "2";
                }
                return {
                  id: item.id,
                  item_name: item.item_name,
                  item_value: valueType,
                };
              }
            }),
            ...this.tableData4.map((item) => {
              return {
                id: item.id,
                item_name: item.item_name,
                item_value: item.item_value,
              };
            }),
            this.auto_accept,
            this.form.data_view_distinguish_transport_type,
            this.form.edit_after_node_finish,
            this.form.maoding_switch,
            this.form.order_auto_waybill,
            this.form.number_verify_switch,
            this.form.waybill_branch_edit,
            this.form.fee_entry,
            this.form.collect_finish_waybill_params_required_check,
            this.form.cost_exceeds_reason_fill_switch,
            this.form.income_cost_fill_switch,
            {
              id: this.form.account_adjust_money_users.id,
              item_name: "account_adjust_money_users",
              item_info: JSON.stringify(
                this.form.account_adjust_money_users.item_info
              ),
              item_value: "1",
            },
            this.form.sign_time_control_switch,
            this.form.distribution_finish_switch,
            show_package_type_quantitydata,
            this.logistics_node_sms_notice,
            this.collect_update_order_waybill_goods,
            this.waybill_collect_time_required,
          ],
        };
      }
      if (this.pitchvalue1 === 0) {
        var infoFindType = this.infoFind();
        if (infoFindType == true) {
          settingCreate(param).then((res) => {
            if (res.code == "10000") {
              this.$message({
                message: "编辑成功",
                type: "success",
              });
            }
          });
        } else {
          this.$message({
            message: "固定字符不能为空",
            type: "warning",
          });
        }
      } else {
        settingCreate(param).then((res) => {
          if (res.code == "10000") {
            this.$message({
              message: "编辑成功",
              type: "success",
            });
          }
        });
      }
    },
    settingListObj() {
      var param = {};
      settingList(param).then((res) => {
        if (res.code == "10000") {
          res.data.settings.forEach((item) => {
            if (item.item_name == "collect_time_required") {
              //提货时间
              let piece = this.tableData1.find(
                (item2) => item2.item_name === item.item_name
              );
              let piece2 = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
              if (piece2) {
                piece2.item_value = item.item_value;
                piece2.id = item.id;
              }
            } else if (item.item_name == "order_aging_required") {
              //订单时效
              let piece = this.tableData1.find(
                (item2) => item2.item_name === item.item_name
              );
              let piece2 = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
              if (piece2) {
                piece2.item_value = item.item_value;
                piece2.id = item.id;
              }
            } else if (item.item_name == "delivery_method") {
              //送货方式
              let piece = this.tableData2.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "degree_of_urgency") {
              //紧急度
              let piece = this.tableData2.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "receipt") {
              this.tableData2[2].id = item.id;
              var item_value_list = [];
              if (item.item_value) {
                if (item.item_value == 3) {
                  item_value_list = ["客户回单", "我司运单"];
                } else if (item.item_value == 0) {
                  item_value_list = ["客户回单"];
                } else if (item.item_value == 1) {
                  item_value_list = ["我司运单"];
                } else if (item.item_value == 2) {
                  item_value_list = [];
                }
              }
              //回单默认值
              // this.tableData2[2].find(
              //   (itempice) => {
              //     // if (itempice.id == 26) {
              //     //   itempice.item_value = item_value_list
              //     // }
              //   }
              // );

              this.tableData2[2].item_value = item_value_list;
            } else if (item.item_name == "order_auto_accept") {
              //订单自动受理
              this.auto_accept.item_value = item.item_value;
              this.auto_accept.id = item.id;
            } else if (item.item_name == "waybill_freight_required") {
              //运费
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "waybill_from_branch_required") {
              //出发网点
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "waybill_to_branch_required") {
              //目的网点
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "waybill_from_region_required") {
              //发站
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "waybill_to_region_required") {
              //到站
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "waybill_router_required") {
              //路由
              let piece = this.tableData3.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "collect_finish_aging_required") {
              //揽收运单时效
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (
              item.item_name == "collect_finish_waybill_goods_required"
            ) {
              //揽收货物信息
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "collect_finish_freight_required") {
              //揽收运费
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (
              item.item_name == "collect_finish_from_branch_required"
            ) {
              //揽收出发网点
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "collect_finish_to_branch_required") {
              //揽收目的网点
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (
              item.item_name == "collect_finish_thermometer_required"
            ) {
              //揽收温度计
              let piece = this.tableData4.find(
                (item2) => item2.item_name === item.item_name
              );
              if (piece) {
                piece.item_value = item.item_value;
                piece.id = item.id;
              }
            } else if (item.item_name == "order_number_generate_rule") {
              // 订单号的生成规则
              let piece = this.tableData5.find(
                (item2) => item2.item_name === item.item_name
              );
              var item_info_lsit = JSON.parse(item.item_info);
              item_info_lsit.push({ key: "", value: "" });
              if (piece) {
                piece.item_info = item_info_lsit;
                piece.id = item.id;
              }
            } else if (item.item_name == "order_number_allow_input") {
              this.order_number_allow_input.id = item.id;
              this.order_number_allow_input.item_value = item.item_value;
            } else if (item.item_name == "order_number_weather_confuse") {
              this.order_number_weather_confuse.id = item.id;
              this.order_number_weather_confuse.item_value = item.item_value;
            } else if (item.item_name == "show_package_type_quantity") {
              this.show_package_type_quantity.id = item.id;
              this.show_package_type_quantity.item_value = item.item_value;
              this.show_package_type_quantity.item_info = item.item_info
                .split(",")
                .map(Number);
            } else if (item.item_name == "logistics_node_sms_notice") {
              this.logistics_node_sms_notice.id = item.id;
              this.logistics_node_sms_notice.item_value = item.item_value;
            } else if (item.item_name == "collect_update_order_waybill_goods") {
              this.collect_update_order_waybill_goods.id = item.id;
              this.collect_update_order_waybill_goods.item_value =
                item.item_value;
            } else if (item.item_name == "waybill_collect_time_required") {
              this.waybill_collect_time_required.id = item.id;
              this.waybill_collect_time_required.item_value = item.item_value;
            } else if (item.item_name == "account_adjust_money_users") {
              this.form.account_adjust_money_users.id = item.id;
              if (item.item_info === "") {
                this.form.account_adjust_money_users.item_info = [];
              } else {
                this.form.account_adjust_money_users.item_info = JSON.parse(
                  item.item_info
                );
              }
            } else {
              this.form[item.item_name] = item;
            }
          });
        }
      });
    },
    cancel() {
      this.settingListObj();
    },
    handleCheckedReturnReceipt() {
      let result = "";

      for (let i = 0; i < this.tableData5[0].item_info.length; i++) {
        if (
          this.tableData5[0].item_info[i].key == 1 ||
          this.tableData5[0].item_info[i].key == 2
        ) {
          result += this.tableData5[0].item_info[i].value;
        } else if (this.tableData5[0].item_info[i].key == 3) {
          if (this.tableData5[0].item_info[i].value == 1) {
            result += "230331";
          } else if (this.tableData5[0].item_info[i].value == 2) {
            result += "20230331";
          }
        } else if (this.tableData5[0].item_info[i].key == 4) {
          if (this.tableData5[0].item_info[i].value == 2) {
            result += "01";
          } else if (this.tableData5[0].item_info[i].value == 3) {
            result += "001";
          } else if (this.tableData5[0].item_info[i].value == 4) {
            result += "0001";
          } else if (this.tableData5[0].item_info[i].value == 5) {
            result += "00001";
          } else if (this.tableData5[0].item_info[i].value == 6) {
            result += "000001";
          } else if (this.tableData5[0].item_info[i].value == 7) {
            result += "0000001";
          } else if (this.tableData5[0].item_info[i].value == 8) {
            result += "00000001";
          } else {
            result += "";
          }
        }
      }

      this.inputValue = result;
    },
    clearValue(item, index) {
      this.tableData5[0].item_info[index].value = "";
    },
    castAbout(item, index) {
      if (
        this.tableData5[0].item_info[index].key == 1 &&
        this.tableData5[0].item_info[index].value != ""
      ) {
        var valuedata = String(this.tableData5[0].item_info[index].value);
        var valuedataList = [valuedata];
        let pdata = {
          fixed_chars: valuedataList,
        };

        numberRule(pdata).then((res) => {
          if (res.code == "10000") {
            if (res.data.is_ok == false) {
              this.$message({
                message: res.data.err_msg,
                type: "warning",
              });
              this.tableData5[0].item_info[index].value = "";
            }
          }
        });
      }
    },
    infoFind() {
      var itemType = true;
      this.tableData5[0].item_info.find((item) => {
        if (item.key == 1) {
          if (item.value == "") {
            itemType = false;
          }
        }
      });
      return itemType;
    },
    //获取所属客户
    customerBoxFn() {
      let data = {
        name: "", //名称
        is_send: "1", //是否为客户 0不  1是客户
        is_receive: "", //是否收货单位  0不是  1是
      };
      customerBox(data).then((res) => {
        if (res.code === 10000) {
          this.customerBoxData = res.data;
        }
      });
    },
  },
};
</script>
<style scoped lang="less">
/deep/ .el-table__cell {
  font-size: 14px;
}

.SystemManagement {
  // padding: 10px;
  // margin-top: 5px;
  // margin-left: 5px;
  background-color: #fff;

  .in_concent_left_1 {
    float: left;
    // flex: 0 0 200px;
    // height: 500px;
    border-right: 1px solid #ededed;

    .in_concent_left_pitch {
      width: 180px;
      height: 40px;
      line-height: 40px;
      padding-left: 20px;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .in_concent_left_pitch:hover {
      height: 40px;
      width: 180px;
      background: #e6f7ff;
      line-height: 40px;
      padding-left: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .choose_itch {
      height: 40px;
      width: 180px;
      background: #e6f7ff;
      line-height: 40px;
      padding-left: 20px;
      color: #2798ff;
      border-right: 4px solid #1890ff;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .in_concent_left_2 {
    float: left;
    // flex: 0 0 239px;
    // height: 500px;
    border-right: 1px solid #ededed;

    .in_concent_left_pitch {
      width: 180px;
      height: 40px;
      line-height: 40px;
      padding-left: 20px;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .in_concent_left_pitch:hover {
      width: 180px;
      height: 40px;
      background: #e6f7ff;
      line-height: 40px;
      padding-left: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .choose_itch {
      width: 180px;
      height: 40px;
      background: #e6f7ff;
      line-height: 40px;
      padding-left: 20px;
      color: #2798ff;
      border-right: 4px solid #1890ff;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .in_concent_button {
      width: 104px;
      margin: 0 auto;
    }
  }
}

.systemtab {
  width: 100%;
  // display: flex;
  // overflow-y: scroll;
  // height: 600px;

  .systemlist {
    width: 100px;
    border-right: 2px solid #ececec;

    .systembottom {
      width: 100%;
      height: 40px;
      text-align: center;
      line-height: 40px;
      background: #e6f7ff;
      color: #309cff;
      box-sizing: border-box;
      border-right: 3px solid #1890ff;
    }
  }

  .systemconcent {
    width: 100%;

    .tableArea {
      padding: 0 20px;
    }
  }

  .tableTitle {
    font-size: 14px;
    padding: 10px 0;
    color: #606266;
  }

  .radioclass {
    margin-left: 40px;
  }
}
</style>